package com.longcai.piaojia.adapter;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.longcai.piaojia.R;
import com.longcai.piaojia.activity.MyIntegrationActivity;
import com.longcai.piaojia.conn.UserInfoIntegralRecordGet;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import java.util.List;

/**
 * Created by Administrator on 2016/8/3.
 */
public class IntegrationListAdapter extends ArrayAdapter<UserInfoIntegralRecordGet.IntegralRecord> {

    private Context context;
    private LayoutInflater layoutInflater;

    public IntegrationListAdapter(Context context, List<UserInfoIntegralRecordGet.IntegralRecord> objects) {
        super(context, 0, objects);

        this.context = context;

        layoutInflater = ((Activity) context).getLayoutInflater();
    }


    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        final ViewHolder viewHolder;

        UserInfoIntegralRecordGet.IntegralRecord integralRecord = getItem(position);

        if (convertView == null) {

            convertView = BoundViewHelper.boundView(viewHolder = new ViewHolder(), ScaleScreenHelperFactory.getInstance().loadView((ViewGroup) layoutInflater.inflate(R.layout.item_integration_list, null)));

            convertView.setTag(viewHolder);

        } else {

            viewHolder = (ViewHolder) convertView.getTag();

        }

//        Log.e("-----------", integralRecord.integral + integralRecord.note + integralRecord.posttime);
        viewHolder.item_integration_integration_tv.setText(integralRecord.integral);
        viewHolder.item_integration_way_tv.setText(integralRecord.note);
        viewHolder.item_integration_time_tv.setText(integralRecord.posttime);

        return convertView;

    }

    private class ViewHolder {

        @BoundView(R.id.item_integration_time_tv) private TextView item_integration_time_tv;
        @BoundView(R.id.item_integration_way_tv) private TextView item_integration_way_tv;
        @BoundView(R.id.item_integration_integration_tv) private TextView item_integration_integration_tv;

    }
}
